package View

import com.trolltech.qt.gui._
import ControllerView.ControllerView
import AndroidProjectFile.ProjectParameters

/**
 * Created by IntelliJ IDEA.
 * User: danymorard
 * Date: 13.04.11
 * Time: 16:51
 * To change this template use File | Settings | File Templates.
 */

class MainInfoView(controller:ControllerView, parent : QWidget)  extends View(controller, parent) {

  /**
   * button to choose a path
   */
  protected var buttonPath = new QPushButton(container)


  /**
   *
   */
  protected var labelNameProject = new QLabel(container)
  protected var labelActivityName = new QLabel (container)
  protected var labelPath = new QLabel(container)
  protected var labelPackage = new QLabel(container)

 var lineEditPath = new QLineEdit(container)


  /**
   *
   */
  var lineEditNameProject = new QLineEdit(container)
  var lineEditActivityName = new QLineEdit (container)



  var containerPackage = new QWidget(container)
  var lineEditPackage = new QLineEdit(containerPackage)
  var labelPackageExample = new QLabel (containerPackage)
  labelPackageExample.hide




  protected var gridLayout = new QGridLayout(container)




  // init View
  this.initView



  /**
   * Initialize the view
   */
   protected def initView {



    // size of the view
    this.setGeometry(OPTION_VIEW_SIZE)

    // set the text
    labelNameProject.setText("Project name")
    labelPackage.setText("Package name")
    labelPath.setText("Project path")
    labelActivityName.setText("Activity name")



    // edit the button browse
    buttonPath.setText("Browse")
    buttonPath.setObjectName(CSS_BROWSE_BUTTON)
    buttonPath.setFixedSize(SIZE_BUTTON_BROWSE)
    buttonPath.clicked.connect(controller, "selectPathFolder()")

    // use to check content of lineEdit
    lineEditActivityName.editingFinished.connect(controller, "checkActivityName()")
    lineEditPackage.textChanged.connect(controller, "checkPackageName()")
    //lineEditPackage.selectionChanged.connect(controller, "defaultPackageName()")
    lineEditNameProject.editingFinished.connect(controller, "checkProjectName()")
    lineEditNameProject.editingFinished.connect(controller, "defaultPackageName()")

    // update next button when all fields are not empty
    lineEditPath.textChanged.connect(controller, "checkEmptyField()")
    lineEditNameProject.textChanged.connect(controller, "checkEmptyField()")
    lineEditPackage.textChanged.connect(controller, "checkEmptyField()")
    lineEditActivityName.textChanged.connect(controller, "checkEmptyField()")


    // container for the package lineEdit and the label
     containerPackage.setFixedHeight(50)
    //labelPackageExample.setText("3 levels min (com.domain.example)")
    labelPackageExample.setObjectName("labelPackage")
    labelPackageExample.setGeometry(0,35,484,20)
    lineEditPackage.setGeometry(0,15,484,20)



    // create the grid layout
    gridLayout.addWidget(labelPath, 0, 0)
    gridLayout.addWidget(lineEditPath, 0, 1)
    gridLayout.addWidget(buttonPath, 0, 2)


    gridLayout.addWidget(labelNameProject, 1, 0)
    gridLayout.addWidget(lineEditNameProject, 1, 1 )

    gridLayout.addWidget(labelActivityName, 2, 0)
    gridLayout.addWidget(lineEditActivityName, 2, 1)

    gridLayout.addWidget(labelPackage, 3, 0)
    gridLayout.addWidget(containerPackage, 3, 1)


     // focus order
     QWidget.setTabOrder(lineEditPath, lineEditNameProject)
     QWidget.setTabOrder(lineEditNameProject,lineEditActivityName)
     QWidget.setTabOrder(lineEditActivityName,lineEditPackage)




  }


    /**
   * Erase all text filed
   */
  def eraseTextField{

    lineEditPath.clear
    lineEditActivityName.clear
    lineEditNameProject.clear
    lineEditPackage.clear
    lineEditPackage.setPlaceholderText("")
  }


  def saveEntries{
    //save entries of first window
    ProjectParameters projectPath = lineEditPath.text
    ProjectParameters projectName = lineEditNameProject.text
    ProjectParameters activityName = lineEditActivityName.text
    ProjectParameters packageName = lineEditPackage.text
  }

}